//
//  CTOfficialWebSiteViewController.m
//  ConstellationTalk_0.1
//
//  Created by riley on 15/7/2.
//  Copyright (c) 2015年 riley chu. All rights reserved.
//

#import "CTOfficialWebSiteViewController.h"
#import "CTLoginView_Def.h"
#import "CTHeader.h"
#import "CTDebugManager.h"
#import "CTAppLanguage.h"
#import <WebKit/WebKit.h>
#import "CTDeviceFunction.h"
#import "UIViewAdditions.h"
#import "MobClick.h"

@interface CTOfficialWebSiteViewController ()
{
    UIWebView *webView;
    UIView *topView;
    
    WKWebView *wkWebView;
}

@end

@implementation CTOfficialWebSiteViewController

//@synthesize showType;

-(void)dealloc
{
    [topView removeFromSuperview];
    topView = nil;
    [webView removeFromSuperview];
    webView = nil;
    [wkWebView removeFromSuperview];
    wkWebView = nil;
    [CTDebugManager showDebugLogInfo:@"dealloc : CTOfficialWebSiteViewController Is Removed!!!"];
}
-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    
    //统计
    [MobClick beginLogPageView:@"CTOfficialWebSiteViewController"];
}
-(void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    
    //统计
    [MobClick endLogPageView:@"CTOfficialWebSiteViewController"];
}



- (void)viewDidLoad {
    [super viewDidLoad];
    [self createThirtPartyTitleView];
    self.view.backgroundColor = [UIColor whiteColor];
    NSURL *url = [NSURL URLWithString:@"http://picopico.yuchats.com"];
    NSURLRequest * request=[NSURLRequest requestWithURL:url];
    
    
    
    if ([CTDeviceFunction deviceSystemVersion] == DeviceSystemVersion_iOS8){
        wkWebView = [[WKWebView alloc] initWithFrame:CGRectMake(0, 64, CT_HEADER_SCREEN_WIDTH, CT_HEADER_SCREEN_HEIGHT-64)];
        [wkWebView loadRequest:request];
        wkWebView.scrollView.bounces = NO;
        wkWebView.backgroundColor = [UIColor clearColor];
        [self.view addSubview:wkWebView];
    }
    else {
        webView=[[UIWebView alloc]initWithFrame:CGRectMake(0, 64, CT_HEADER_SCREEN_WIDTH, CT_HEADER_SCREEN_HEIGHT-64)];
        [webView loadRequest:request];
        webView.scrollView.bounces = NO;
        webView.backgroundColor=[UIColor clearColor];
        [self.view addSubview:webView];
    }
    
    

    // Do any additional setup after loading the view.
}
- (void)createThirtPartyTitleView
{
    topView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, CT_HEADER_SCREEN_WIDTH, 64)];
    topView.backgroundColor = CT_HEADER_WHITE_COLOR;
    [self.view addSubview:topView];
    
    //标题
    UILabel *titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 20, CT_HEADER_SCREEN_WIDTH, 44)];
    titleLabel.font = [UIFont fontWithName:nil size:19.0f];
    titleLabel.text = [CTAppLanguage localizedStringForKey:@"offical_title" withValue:nil withTable:@"Language"];
    titleLabel.textColor = CT_HEADER_GREEN_COLOR;
    titleLabel.textAlignment = NSTextAlignmentCenter;
    [topView addSubview:titleLabel];
    
//    if (showType == CTUserAgreementViewControllerShowTypePresent) {
//        //取消
//        UIButton *cancelButton = [UIButton buttonWithType:UIButtonTypeCustom];
//        cancelButton.frame = CGRectMake(CT_HEADER_SCREEN_WIDTH-44,20 , 44, 44);
//        [cancelButton addTarget:self action:@selector(cancelButtonAction:) forControlEvents:UIControlEventTouchUpInside];
//        cancelButton.titleLabel.font = [UIFont systemFontOfSize:15.0f];
//        [cancelButton setTitle:[CTAppLanguage localizedStringForKey:@"userAgreementViewControl_cancel_text" withValue:nil withTable:@"Language"] forState:UIControlStateNormal];
//        [cancelButton setTitleColor:CT_HEADER_GREEN_COLOR forState:UIControlStateNormal];
//        [cancelButton setTitleColor:CT_HEADER_GREEN_COLOR forState:UIControlStateHighlighted];
//        [topView addSubview:cancelButton];
//    }else{
        //返回按钮
        UIButton *backButton = [UIButton buttonWithType:UIButtonTypeCustom];
        backButton.frame = CGRectMake(0, 20, 44, 44);
        [backButton addTarget:self action:@selector(backBtnAction:) forControlEvents:UIControlEventTouchUpInside];
        [backButton setImage:[UIImage imageNamed:CT_HEADER_BACK_IMAGE] forState:UIControlStateNormal];
        [backButton setImage:[UIImage imageNamed:CT_HEADER_BACK_IMAGE_CLICK] forState:UIControlStateHighlighted];
        [topView addSubview:backButton];
//    }
    
    UILabel * topBottomLine = [[UILabel alloc]initWithFrame:CGRectMake(0, topView.height-0.5, CT_HEADER_SCREEN_WIDTH, 0.5)];
    topBottomLine.backgroundColor = CT_HEADER_DEEPLINE_COLOR;
    [topView addSubview:topBottomLine];
}
- (void)cancelButtonAction:(UIButton *) sender
{
    [self dismissViewControllerAnimated:YES completion:^{
        
    }];
}
-(void)backBtnAction:(id)sender
{
    [self.navigationController popViewControllerAnimated:YES];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
